package YuanFuDao2;

import java.util.Stack;

/**
 * 两个栈实现队列
 */
public class Main19 {
    public static void main(String[] args) {
        CQueue queue = new CQueue();
        System.out.println(queue.deleteHead());

        queue.appendTail(3);
        queue.appendTail(9);
        queue.appendTail(2);
        System.out.println(queue.deleteHead());

    }
}


class CQueue {

    private Stack<Integer> stack1;
    private Stack<Integer> stack2;
    public CQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void appendTail(int value) {
        stack1.push(value);
    }

    public int deleteHead() {
        if(!stack2.isEmpty()){
            return stack2.pop();
        }else{
            while(!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
            if(!stack2.isEmpty()){
                return stack2.pop();
            }
        }


        return -1;
    }
}

